package huian.lee.web.action;

import org.apache.struts2.ServletActionContext;

import huian.lee.entity.Userinfo;
import huian.lee.service.ServiceFactory;
import huian.lee.service.UserinfoService;

public class UserinfoAction {
 private Userinfo userinfo;
 private ServiceFactory serviceFactory;
 private UserinfoService userinfoService;
 private String tag;
public Userinfo getUserinfo() {
	return userinfo;
}
public void setUserinfo(Userinfo userinfo) {
	this.userinfo = userinfo;
}


public UserinfoService getUserinfoService() {
	return userinfoService;
}
public void setUserinfoService(UserinfoService userinfoService) {
	this.userinfoService = userinfoService;
}
public ServiceFactory getServiceFactory() {
	return serviceFactory;
}
public void setServiceFactory(ServiceFactory serviceFactory) {
	this.serviceFactory = serviceFactory;
}

public String register()
{
 return "success";
}
public String doregister()
{
	userinfo=this.userinfoService.saveUserinfo(userinfo);
	if(userinfo!=null)
	return "success";
	else return "error";
}
public String dologin()
{
	String password=userinfo.getPassword();
    userinfo=this.userinfoService.getUserinfoByEmail(userinfo.getEmail()); 
 
    if(userinfo!=null)
    {
     
    	 if(password.equals(userinfo.getPassword()))
    	 {
    		 ServletActionContext.getRequest().getSession().putValue("userinfo",userinfo);
    		 return "success";
    	 }
    	 else 
    	 {
    		 tag="用户密码错误";
    		 return "error";
    	 }
    	 
    }else
    {
      tag="用户不存在";
	   return "error";
    }
  }
public String login()
{
	
	return "success";
}

}
